package com.sinosoft.dsp.system.core.i18n;

import java.util.Locale;

import com.sinosoft.dsp.system.core.property.BasePropertyHandler;
import com.sinosoft.dsp.system.utils.Const;

/**
 * 语言选择器
 * 
 * @author 潘巍（Peter Pan）
 * @since 2011-4-20 下午01:27:17
 */
public class LanguageChoice {

	private static LanguageChoice choice;

	// 默认区域
	private Locale defaultLocale;

	// 偏好区域
	private Locale failoverLocale;

	private LanguageChoice() {
		String def = BasePropertyHandler.getProperty("Sino.Default.Locale");
		if (Const.isEmpty(def)) {
			defaultLocale = Const.DEFAULT_LOCALE;
		} else {
			String[] defArr = def.split("_");
			if (defArr.length == 2) {
				defaultLocale = new Locale(defArr[0], defArr[1]);
			} else {
				defaultLocale = new Locale(def);
			}
		}
		failoverLocale = Locale.US;
	}

	public static final LanguageChoice getInstance() {
		if (choice != null)
			return choice;

		choice = new LanguageChoice();

		return choice;
	}

	/**
	 * @return 返回默认区域
	 */
	public Locale getDefaultLocale() {
		return defaultLocale;
	}

	/**
	 * @param defaultLocale
	 *            设置默认区域
	 */
	public void setDefaultLocale(Locale defaultLocale) {
		this.defaultLocale = defaultLocale;
	}

	/**
	 * @return 返回偏好区域
	 */
	public Locale getFailoverLocale() {
		return failoverLocale;
	}

	/**
	 * @param failoverLocale
	 *            设置偏好区域
	 */
	public void setFailoverLocale(Locale failoverLocale) {
		this.failoverLocale = failoverLocale;
	}

}
